package com.aviccxzx.smarthome.base;

import android.util.Log;


import com.xiaowei.core.CoreApplication;

import java.util.Stack;

/**
 * Created by juyang on 16/3/22.
 */
public class MainApplication extends CoreApplication implements IHandlerLikeNotify {
    private String TAG = "MainApplication";

    private static MainApplication instance;
    private IHandlerLikeNotify currentNotify;
    private Stack<BaseActivity> activityStack;


    @Override
    public void onCreate() {
        super.onCreate();
        activityStack = new Stack<BaseActivity>();

        currentNotify = null;

        instance = this;
    }

    public static MainApplication getInstance() {
        return instance;
    }


    /**
     * 修改当前显示的 Activity 引用
     *
     * @param currentNotify
     */
    public void setCurrentNotify(IHandlerLikeNotify currentNotify) {
        this.currentNotify = currentNotify;
    }

    public IHandlerLikeNotify getCurrentNotify() {
        return currentNotify;
    }


    @Override
    public void onNotify(int what, int arg1, int arg2, Object obj) {

    }

    /**
     * 底层所有的回调接口
     *
     * @param what
     * @param uchType
     * @param channel
     * @param obj
     */
    public synchronized void onJniNotify(int what, int uchType, int channel, Object obj) {
        if (null != currentNotify) {
            currentNotify.onNotify(what, uchType, channel, obj);
        } else {
            Log.e(TAG, "currentNotify is null!");
        }

    }

    /**
     * activity 入栈
     *
     * @param activity
     */
    public void push(BaseActivity activity) {
        activityStack.push(activity);
    }

    /**
     * activity 出栈
     */
    public BaseActivity pop() {
        return (false == activityStack.isEmpty()) ? activityStack.pop() : null;

    }
}
